package com.gxa.ehome.web.servlet;

import com.gxa.ehome.exception.BusinessException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "TestExceptionServlet",urlPatterns = "/test.do")
public class TestExceptionServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//抛出异常
        try {
            throw new BusinessException("这是我们自定义的测试异常");
        } catch (BusinessException e) {
//            e.printStackTrace("e",e);
            request.setAttribute("e",e);

        }

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


//            throw new BusinessException("这是我们自定义的测试异常");


    }
}
